package com.gnkexy.springframework.test;

import com.gnkexy.springframework.beans.BeansException;
import com.gnkexy.springframework.beans.factory.support.BeanFactory;
import com.gnkexy.springframework.context.ApplicationContext;
import com.gnkexy.springframework.context.supper.ClassPathXmlApplicationContext;
import com.gnkexy.springframework.test.bean.UserService;
import org.junit.Test;

public class ApiTest5 {

    //单元测试(单例&原型)
    @Test
    public void test_xml01() throws BeansException {
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring.xml");
        applicationContext.registerShutdownHook();

        UserService userService = (UserService) applicationContext.getBean("userService");
        UserService userService2 = (UserService) applicationContext.getBean("userService");

        System.out.println(userService);
        System.out.println(userService2);
    }

    //单元测试(代理对象)
    @Test
    public void test_xml02() throws BeansException {
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring.xml");
        applicationContext.registerShutdownHook();

        UserService userService = (UserService) applicationContext.getBean("userService");
        System.out.println("测试结果："+userService.queryUserInfo());
    }

}
